package com.atguigu.dga.governance.assessor.calc;

import com.atguigu.dga.common.MetaConst;
import com.atguigu.dga.ds.bean.TDsTaskInstance;
import com.atguigu.dga.governance.assessor.Assessor;
import com.atguigu.dga.governance.bean.AssessParam;
import com.atguigu.dga.governance.bean.GovernanceAssessDetail;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

@Component("HAS_FAILED_TASK")
public class HasFailedTaskAssessor extends Assessor {
    @Override
    protected void assessProblem(GovernanceAssessDetail governanceAssessDetail, AssessParam assessParam) throws Exception {
        List<TDsTaskInstance> dsTaskInstanceList = assessParam.getTDsTaskInstanceList();
        if(dsTaskInstanceList==null||dsTaskInstanceList.size()==0){
            return;
        }

        boolean hasFailedTask=false;
        for (TDsTaskInstance tDsTaskInstance : dsTaskInstanceList) {
            if( tDsTaskInstance.getState().toString().equals(MetaConst.TASK_STATE_FAILED.toString())){  //魔法值
                hasFailedTask=true;
            }
        }

        if(hasFailedTask){
            governanceAssessDetail.setAssessScore(BigDecimal.ZERO);
            governanceAssessDetail.setAssessProblem("存在失败任务");
        }

    }
}
